@extends('layouts/app')
@section('content')
{{-- table房桌管理--}}

<div class="weui-teb table-code">
    <div class="tab-content">
        <div class="weui-grids ">
            {{--<a href="" class="weui-grid js_grid">--}}
               {{----}}
            {{--</a>--}}
        </div>
    </div>

    <div class="weui-gallery" style="display: none">
        <span class="weui-gallery__img" id="weui-gallery__img"></span>
        <div class="weui-gallery__opr down-btn">
            <a href="javascript:" class="weui-gallery__del" onclick="downloadClick(this)">
                下载
            </a>
        </div>
    </div>
</div>
<script src="/qrcodejs-master/qrcode.js"></script>
<script>
    var id = getRequest().id;


    //所有房桌
      function grtRoomtablea() {
          $.post("/api/shop/showRoomTable",{shop_id:id},function(res){
                 if(typeof res === 'string'){
                     res = JSON.parse(res);
                 }
              console.log("res",res);
              if(res.code == 200) {
                  var data ={};
                  data['type'] = 'talbeCodeList';
                  data['element'] =".tab-content .weui-grids";
                  data['data'] = res.data;
                  A.init(data);

                  $(".weui-grids .js_grid").each(function () {
                      var id = $(this).attr("id"),
                          url = location.origin + "/s?id=" + id;

                      console.log("id", id);

                      makeCode(url, id);

                  });
              }
          });
      }
      grtRoomtablea();

    // 生成二维码
    function makeCode (url, id) {

        var qrcode = new QRCode(id, {
            width: 100,
            height: 100
        });
        qrcode.makeCode(url); // 更换二维码内容
    }

    // 点击查看大图
    $(".weui-grids").on("click", ".js_grid", function () {
        var id = $(this).attr("id"),
        url = location.origin + "/s?id=" + id;

        makeBigCodeImg(url);

        $(".weui-gallery").show();

    });

    // 创建大的二维码
    function makeBigCodeImg (url) {
        var qrcode1 = new QRCode("weui-gallery__img", {
            text: url,
            width: 256,
            height: 256
        });
    }
    // 点击下载图片
    function downloadClick (e) {
        var url = $("#weui-gallery__img img").attr("src");
        $(e).attr("href", url).attr("download", "二维码.png");

    }

    $(".weui-gallery").click(function () {
        makeBigCodeImg('');
        $(this).hide();
    });
</script>
@endsection
@extends('layouts/footer')
